<table class="ui celled striped table">
  <thead>
    <tr>
      <th></th>
    <%= if Policies.Admin.Podcast.create(@current_user) do %>
      <th>Position</th>
    <% end %>
      <th>Status</th>
      <th>Twitter</th>
      <th>Subscribers</th>
      <th>Episodes</th>
      <th>Downloads</th>
      <th></th>
    </tr>
  </thead>

  <tbody>
  <%= for podcast <- @podcasts do %>
    <tr>
      <td class="center aligned">
        <%= link to: ~p"/admin/podcasts/#{podcast.slug}/episodes" do %>
        <h2 class="ui image header">
          <img src="<%= cover_url(podcast, :small) %>" class="ui image" />
        </h2>
        <% end %>
      </td>
    <%= if Policies.Admin.Podcast.create(@current_user) do %>
      <td><%= podcast.position %></td>
    <% end %>
      <td><%= status_label(podcast) %></td>
      <td><%= SharedHelpers.twitter_link(podcast) %></td>
      <td>
        <strong>Email:</strong> <%= link(SharedHelpers.comma_separated(Podcast.subscription_count(podcast)), to: Routes.admin_podcast_subscription_path(@conn, :index, podcast.slug)) %><br/>
      <%= for {client, count} <- (podcast.subscribers || %{}) do %>
        <strong><%= client %>:</strong> <%= SharedHelpers.comma_separated(count) %><br/>
      <% end %>
      </td>
      <td><%= episode_count(podcast) %></td>
      <td><%= SharedHelpers.pretty_downloads(podcast) %></td>
      <td class="center aligned">
        <div class="ui small basic buttons">
          <%= AdminHelpers.icon_link("eye", to: Routes.podcast_path(@conn, :show, podcast.slug)) %>
          <%= AdminHelpers.icon_link("refresh", to: Routes.admin_podcast_path(@conn, :feed, podcast.slug), method: :post, title: "Refresh Feed") %>
        <%= if Policies.Admin.Podcast.edit(@current_user, podcast) do %>
          <%= AdminHelpers.icon_link("edit", to: Routes.admin_podcast_path(@conn, :edit, podcast.slug)) %>
        <% end %>
          <%= AdminHelpers.icon_link("list", to: ~p"/admin/podcasts/#{podcast.slug}/episodes") %>
        <%= if Policies.Admin.Episode.new(@current_user, podcast) do %>
          <%= AdminHelpers.icon_link("add", to: Routes.admin_podcast_episode_path(@conn, :new, podcast.slug)) %>
        <% end %>
        </div>
      </td>
    </tr>
  <% end %>
  </tbody>
</table>
